package com.zego.wawaji.ui.bean.wawa;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.zego.wawaji.base.data.BaseData;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 娃娃机
 * Created by Su on 2017/12/3.
 */
public class WawaJi extends BaseData implements Parcelable {
    private long id;       // 娃娃机id
    private String imei;  // 设备号
    private String nickName;// 娃娃机昵称
    private int price;      // 游戏价格
    private String picUrl;  // 封面图片地址
    private int status;     // 娃娃机状态 1:当前空闲 -1：使用中 -2:休息 -3:隐藏
    private int wwTypeId;   // 娃娃id
    private List<String> TipsList;  // 房间提示
    private String msgJson;  // 当前房间消息串

    private String roomId;  // 娃娃机房间id
    private String stream1_id;    // 推流1
    private String stream2_id;    // 推流2

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);

        this.setId(jsonObject.optLong("Id"));
        this.setWwTypeId(jsonObject.optInt("WwTypeId"));
        this.setImei(jsonObject.optString("Imei"));
        this.setNickName(jsonObject.optString("NickName"));
        this.setPrice(jsonObject.optInt("AmountWwCoin"));
        this.setPicUrl(jsonObject.optString("PicUrl"));
        this.setStatus(jsonObject.optInt("WwjStatus"));
        this.setRoomId(jsonObject.optString("RoomId"));
        this.setStream1_id(jsonObject.optString("Stream01"));
        this.setStream2_id(jsonObject.optString("Stream02"));
        this.setTipsList(jsonObject.optString("TipJson"));
        this.setMsgJson(jsonObject.optString("MsgJson"));
    }

    public List<String> getTipsList() {
        return TipsList;
    }

    public void setTipsList(String tips) {
        if (TextUtils.isEmpty(tips))
            return;

        JSONObject jsonObject = getJsonObject(tips);
        if (jsonObject == null && jsonObject.isNull("Content"))
            return;

        if (TipsList == null)
            TipsList = new ArrayList<>();

        TipsList.clear();
        try {
            JSONArray jsonArray = new JSONArray(jsonObject.optString("Content"));
            if (jsonArray == null) return;

            for (int i = 0; i < jsonArray.length(); i++) {
                TipsList.add(jsonArray.optString(i));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return;
    }

    public String getMsgJson() {
        return msgJson;
    }

    public void setMsgJson(String msgJson) {
        this.msgJson = msgJson;
    }

    public int getWwTypeId() {
        return wwTypeId;
    }

    public void setWwTypeId(int wwTypeId) {
        this.wwTypeId = wwTypeId;
    }

    public String getRoomId() {
        return roomId;
    }

    public void setRoomId(String roomId) {
        this.roomId = roomId;
    }

    public String getStream1_id() {
        return stream1_id;
    }

    public void setStream1_id(String stream1_id) {
        this.stream1_id = stream1_id;
    }

    public String getStream2_id() {
        return stream2_id;
    }

    public void setStream2_id(String stream2_id) {
        this.stream2_id = stream2_id;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getImei() {
        return imei;
    }

    public void setImei(String imei) {
        this.imei = imei;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getPicUrl() {
        return picUrl;
    }

    public void setPicUrl(String picUrl) {
        this.picUrl = picUrl;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @Override
    public String toString() {
        return "Wawa{" +
                "id=" + id +
                ", imei='" + imei + '\'' +
                ", nickName='" + nickName + '\'' +
                ", price=" + price +
                ", picUrl='" + picUrl + '\'' +
                ", status=" + status +
                ", roomId='" + roomId + '\'' +
                ", stream1_id='" + stream1_id + '\'' +
                ", stream2_id='" + stream2_id + '\'' +
                '}';
    }


    public WawaJi() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeString(this.imei);
        dest.writeString(this.nickName);
        dest.writeInt(this.price);
        dest.writeString(this.picUrl);
        dest.writeInt(this.status);
        dest.writeInt(this.wwTypeId);
        dest.writeStringList(this.TipsList);
        dest.writeString(this.msgJson);
        dest.writeString(this.roomId);
        dest.writeString(this.stream1_id);
        dest.writeString(this.stream2_id);
    }

    protected WawaJi(Parcel in) {
        this.id = in.readLong();
        this.imei = in.readString();
        this.nickName = in.readString();
        this.price = in.readInt();
        this.picUrl = in.readString();
        this.status = in.readInt();
        this.wwTypeId = in.readInt();
        this.TipsList = in.createStringArrayList();
        this.msgJson = in.readString();
        this.roomId = in.readString();
        this.stream1_id = in.readString();
        this.stream2_id = in.readString();
    }

    public static final Creator<WawaJi> CREATOR = new Creator<WawaJi>() {
        @Override
        public WawaJi createFromParcel(Parcel source) {
            return new WawaJi(source);
        }

        @Override
        public WawaJi[] newArray(int size) {
            return new WawaJi[size];
        }
    };
}
